﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace Rio.Manager.Application.Converters
{
    public class BooleanToVisibilityConverter : IValueConverter
    {
        #region Methods

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (String.IsNullOrWhiteSpace(parameter as string))
            {
                if (value == null)
                    return Visibility.Collapsed;

                var isVisible = (bool)value;

                return isVisible ? Visibility.Visible : Visibility.Collapsed;
            }
            else
            {
                if (value == null)
                    return Visibility.Visible;

                var isVisible = (bool)value;

                return isVisible ? Visibility.Collapsed : Visibility.Visible;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var visiblity = (Visibility)value;

            return visiblity == Visibility.Visible;
        }

        #endregion Methods
    }
}